/**
 *选择时间的js文件
 */
$(function() {
	var webroot = $("#webRoot").val();
	$("#time").click(function() {
		var date = new Date();
		var miDate = date.getTime();
		var time = ["8:00-10:00", "10:00-12:00", "14:00-16:00", "16:00-18:00", "18:00-夜间"];
		var node = "<div id='date'><ul>";
		var arr = getFirstHour(time,date.getHours()+1);
		var fullDate = date.getFullYear() + "年" + (date.getMonth() + 1) + "月" +
				date.getDate() + "日 ";
		for(var i = 0;i<arr.length;i++) {
             node += "<li>" + fullDate + "     " + arr[i] + "</li>";
		}
		for (var i = 1; i < 3; i++) {
			miDate = miDate + 1 * 24 * 60 * 60 * 1000;
			var d = new Date(miDate);
			var fullDate = d.getFullYear() + "年" + (d.getMonth() + 1) + "月" +
				d.getDate() + "日 ";
			for (var j = 0; j < time.length; j++) {
				node += "<li>" + fullDate + "     " + time[j] + "</li>";
			}
		}
		node + "</ul></div>";
		$("body").dialog({
			message: node,
			footHeight: 0,
			title: "请选择适合您的时间段",
			width: "100%",
			isCenter: false,
			top: 0,
			left: 0,
			height: 820

		});
		$("#date ul li").click(function() {
			var v = $(this).html();
			var d = {
				"time": $(this).html()
			};
			var url = webroot + "/wx/time/save";
			$.post(url, d, function(data) {
				$(".show_time").html(v);
				$(".show_time").show();
				$(".show_time").addClass("hasMessage");
				$("#hidden_time").val(v);
				$("#hg_sade").remove();
				$("#hg_dialog").remove();
			});

		});
	});
});
function getFirstHour(times,curHour) {
	var arr = [];
	for(var i = 0;i<times.length-1;i++) {
		var time = times[i];
		var  hour = parseInt(time.substring(0,2));
		if(hour-curHour>=2) {
			arr.push(time);
		}
	}
	arr.push(times[i]);
	return arr;
}